#include "MRect.h"
#include <GL\glut.h>
MRect::MRect(float x1,float y1,float x2,float y2) {
	speed = 0;
	p1.first = x1;
	p1.second = y1;
	p2.first = x2;
	p2.second = y2;
	name = "RECT";
	w = x2 - x1;
	h = y2 - y1;
}

MRect::~MRect(void)
{

}


void MRect::drawShape() {
	glColor3f(cr,cg,cb);
	glRectf(p1.first,p1.second,p2.first,p2.second);
}

void MRect::fallDown(float t, list<Shape*> *l1 ) {
	if(bStop) //if object on the plane 
		return;
	float offset = speed*t+.5*Shape::acceleration*t*t;	//fall down distance
	speed += Shape::acceleration*t;


	if(p1.second - offset >=0) {	//if the object above the plane
		p1.second -= offset;
		p2.second -= offset;
	}
	else {	//an object cant fall below the plane
		p2.second = p2.second - p1.second;
		p1.second = 0;
		speed = 0;
		bStop = true;
	}

	CollisionDetector::collisionDetect(this,l1);
}

void MRect::shift(float x, float y) {

}

float MRect::getMinX() const {
	return p1.first;
}

float MRect::getMaxX() const {
	return p2.first;
}